import jieba

def count_word_frequency(file_path):

    word_count = {}
    with open(file_path, 'r', encoding='utf-8') as file:
        # 逐行读取文件内容
        for line in file:
            # 使用jieba分词
            words = jieba.lcut(line.strip())
            # 统计词频
            for word in words:
                if word in word_count:
                    word_count[word] += 1
                else:
                    word_count[word] = 1
    sorted_word_count = sorted(word_count.items(), key=lambda x: x[1], reverse=True)
    for word, frequency in sorted_word_count:
        print(f"{word}: {frequency}")

# 输入“三国演义”文本文件路径
file_path = "三国演义.txt"
count_word_frequency(file_path)
